<template>
	<div>

		<div class="app-container">

			<TopInfo />

			<Search :lookup="data.lookup" @investigate="inves" />

		</div>

		<div class="app-container" v-loading="data.mtloading">
			<el-table :data="data.list" :header-cell-style="{ 'text-align': 'center' }"
				:cell-style="{ 'text-align': 'center' }" class="w-full" height="700">
				<el-table-column prop="creator_nickname" :label="$t('exportLog.name')" />
				<el-table-column prop="export_position" :label="$t('exportLog.page')" />
				<el-table-column prop="file_name" :label="$t('exportLog.file')" />
				<el-table-column :label="$t('exportLog.status')">
					<template #default="scope">
						{{ setStatus(scope.row) }}
					</template>
				</el-table-column>
				<el-table-column :label="$t('exportLog.time')">
					<template #default="scope">
						{{ getPlevel.gettime(scope.row.request_time, 3) }}
					</template>
				</el-table-column>
				<el-table-column :label="$t('date.exportTime')">
					<template #default="scope">
						{{ getPlevel.gettime(scope.row.export_time, 3) }}
					</template>
				</el-table-column>
				<el-table-column :label="$t('public.operate')">
					<template #default="scope">
						<span v-if="scope.row.status == 2" class="text-[#409EFF] cursor-pointer"
							@click="onDownload(scope.row)">{{ $t('public.download') }}</span>
						<span v-if="scope.row.status == 4 || scope.row.status == 1">{{ $t('exportLog.downloaded') }}</span>
						<span v-if="scope.row.status == 3">{{ $t('exportLog.expired') }}</span>
					</template>
				</el-table-column>
			</el-table>
			<PageNum :total="data.total" :page="data.info" @exposeData="current" @fraction="fraction" />
		</div>

	</div>
</template>

<script lang="ts" setup>
import { useI18n } from 'vue-i18n'
const { t: $t } = useI18n()
import getPlevel from "@/utils/level";
import TopInfo from '@/components/TopInfo/index.vue';
import Search from '@/components/Search/index.vue';
import PageNum from '@/components/PageNum/index.vue';
import { exportLogList } from '@/api/exportLog'
import { exportData } from "@/utils/excel";
let onDownload = (row: any) => {
	exportData(row.file_path, row.file_name, 2)
}
let data = reactive({
	mtloading: false, // 加载
	lookup: [ // 筛选栏
		{
			title: $t('exportLog.status'), type: 'define', value: '', select: [
				{ label: $t('public.progress'), value: 1 },
				{ label: $t('public.generated'), value: 2 },
				{ label: $t('public.expired'), value: 3 },
				{ label: $t('public.failed'), value: 4 }
			], key: 'status'
		},
		{ title: $t('date.exportTime'), type: 'time', value: '', key: 'time' },
	],
	list: [], // 列表信息
	info: { // 筛选数据
		page: 1,
		pageNum: 15,
		status: '',
		export_time: ''
	},
	total: 0, // 总条数
})
let setStatus = (row: any) => {
	if (row.status == 1) {
		row.statusCn = $t('public.progress')
	}
	if (row.status == 2) {
		row.statusCn = $t('public.generated')
	}
	if (row.status == 3) {
		row.statusCn = $t('public.expired')
	}
	if (row.status == 4) {
		row.statusCn = $t('public.failed')
	}
	return row.statusCn
}
// 获取列表信息
let getlist = () => {
	data.mtloading = true
	exportLogList(data.info)
		.then((res) => {
			data.mtloading = false
			if (res.state == 200) {
				data.list = res.data.data;
				data.total = res.data.total
			}
		}).catch((err) => { });
};
// 查询回调
let inves = (e) => {
	data.info.create_time = ''
	for (let key in e) {
		if (key != 'time') {
			data.info[key] = e[key]
		}
	}
	if (e.time != '') {
		data.info.create_time = e.time[0] + ' ' + '00:00:00' + '~' + e.time[1] + ' ' + '23:59:59'
	}
	data.info.page = 1
	data.info.pageNum = 15
	getlist()
}

// 页数回调
let current = (e) => {
	data.info.page = e
	getlist()
}

// 条数回调
let fraction = (e) => {
	data.info.pageNum = e
	getlist()
}
getlist()

</script>
